<?php
// Copyright 2019 Hackware SpA <human@hackware.cl>
// This file is part of "Hackware Web Services Payment" and licensed under
// the terms of the GNU Affero General Public License version 3, or (at your
// option) a later version. You should have received a copy of this license
// along with the software. If not, see <https://www.gnu.org/licenses/>.

namespace Hawese\Payment\Providers;

use Illuminate\Support\ServiceProvider;

class PaymentServiceProvider extends ServiceProvider
{
    const BASEDIR = __DIR__ . '/../..';

    public function register()
    {
        // General package config (not gateways)
        $this->mergeConfigFrom(
            self::BASEDIR . '/config/payment.php',
            'payment'
        );

        // Load gateway config
        foreach (['flow', 'khipu'] as $gateway) {
            $this->mergeConfigFrom(
                self::BASEDIR . "/config/gateways/$gateway.php",
                "gateways.$gateway"
            );
        }
    }

    public function boot()
    {
        $this->loadRoutesFrom(self::BASEDIR . '/routes/payment.php');
        $this->loadMigrationsFrom(self::BASEDIR . '/database/migrations');

        // Policies
        $this->app['gate']->policy(
            Hawese\Payment\Payment::class,
            Hawese\Payment\Policies\PaymentPolicy::class
        );
    }
}
